<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			var fun=function(x){
				let n1=document.getElementById("num1").value;
				let n2=document.getElementById("num2").value;
				
				if(isNaN(n1)||isNaN(n2)){
				     alert("输入内容不是数字！");
					 return;
				}
				
				n1=n1-0;
				n2=n2-0;
				
				if(x==1){
					var res = n1+n2;
					res=res.toFixed(16)-0;
					document.getElementById("num3").value=res;
					return;
				}
				else if(x==2){
					var res = n1-n2;
					document.getElementById("num3").value=res;
					return;
				}
				else if(x==3){
					var res = n1*n2;
					document.getElementById("num3").value=res;
					return;
				}
				else if(x==4){
					if(n2==0){
						alert("除数不能为0！");
						return;
					}
					else{
					var res = n1/n2;
					document.getElementById("num3").value=res;
					return;
					}
				}
			}
		</script>
	</head>
	<body>
		第一个数：<input type="text" id="num1"/><br>
		第二个数：<input type="text" id="num2"/><br>
		<button type="button" onclick="fun(1)">+</button>
		<button type="button" onclick="fun(2)">-</button>
		<button type="button" onclick="fun(3)">*</button>
		<button type="button" onclick="fun(4)">/</button><br>
		计算结果：<input type="text" id="num3"/>
	</body>
</html>
